package cn.cheneyjoo.controller;

import cn.cheneyjoo.model.Employee;
import cn.cheneyjoo.model.EmployeeExtend;
import cn.cheneyjoo.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {
    //注入员工服务类
    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<EmployeeExtend> allEmployee = employeeService.findAll();
        model.addAttribute("list",allEmployee);
        return "list";
    }

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public String save(Employee employee){
        employeeService.save(employee);
        return "redirect:/employee/findAll";
    }
}
